<?php

use yii\helpers\Html;
use yii\grid\GridView;
use mdm\admin\components\RouteRule;
use mdm\admin\components\Configs;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $searchModel mdm\admin\models\searchs\AuthItem */
/* @var $context mdm\admin\components\ItemController */

$context = $this->context;
$labels = $context->labels();
$this->title = '角色';
if( $labels['Items'] == 'Permissions'){
    $this->title = '权限';
}

$this->params['breadcrumbs'][] = $this->title;

$rules = array_keys(Configs::authManager()->getRules());
$rules = array_combine($rules, $rules);
unset($rules[RouteRule::RULE_NAME]);
?>
<div class="role-index">

    <p>
        <?= Html::a( '<i class="icon ion-plus"></i> ' .$this->title, ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'summary' => "第{begin} - {end}条   共{totalCount}条数据",
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [
                'attribute' => 'name',
                'label' => '名称',
            ],
            [
                'attribute' => 'ruleName',
                'label' => '规则',
                'filter' => $rules
            ],
            [
                'attribute' => 'description',
                'label' => '描述',
            ],
            ['class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{view} {update} {delete}',
                'buttons' => [
                    'view' => function ($url,$model,$key)   { return Html::a('绑定', [$url], ['title' => '绑定','class'=>"btn btn-primary btn-sm"]); },
                    'update' => function ($url,$model,$key) { return Html::a('编辑', [$url], ['title' => '编辑','class'=>'btn btn-default btn-sm']); },
                    'delete' => function ($url,$model, $key) { return Html::a('删除', [$url], ['title' => '删除', 'data-method' => 'post','data-confirm' => "sure delete?", 'class' => 'btn btn-danger btn-sm',]);},

                ],
            ],
        ],
    ])
    ?>

</div>
